package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.vo.resp.HomeRespVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import java.util.Random;

import com.company.project.common.utils.DataResult;

import com.company.project.entity.SysSmscodeEntity;
import com.company.project.service.SysSmscodeService;



/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-10-19 15:40:26
 */
@Controller
@RequestMapping("/")
public class SysSmscodeController {
    @Autowired
    private SysSmscodeService sysSmscodeService;

    @GetMapping("/smscode/{phone}")
    @RequiresPermissions("tSeats:update")
    @ApiOperation(value = "获取验证码")
    @ResponseBody
    public DataResult getSmscode(@PathVariable("phone") String phone) {
        return sysSmscodeService.getSmscode(phone);
    }

    /**
    * 跳转到页面
    */
    @GetMapping("/index/sysSmscode")
    public String sysSmscode() {
        return "syssmscode/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("sysSmscode/add")
    @RequiresPermissions("sysSmscode:add")
    @ResponseBody
    public DataResult add(@RequestBody SysSmscodeEntity sysSmscode){
        sysSmscodeService.save(sysSmscode);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("sysSmscode/delete")
    @RequiresPermissions("sysSmscode:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        sysSmscodeService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("sysSmscode/update")
    @RequiresPermissions("sysSmscode:update")
    @ResponseBody
    public DataResult update(@RequestBody SysSmscodeEntity sysSmscode){
        sysSmscodeService.updateById(sysSmscode);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("sysSmscode/listByPage")
    @RequiresPermissions("sysSmscode:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SysSmscodeEntity sysSmscode){
        Page page = new Page(sysSmscode.getPage(), sysSmscode.getLimit());
        LambdaQueryWrapper<SysSmscodeEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(SysSmscodeEntity::getId, sysSmscode.getId());
        IPage<SysSmscodeEntity> iPage = sysSmscodeService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
